/**
 * 
 */
package wpmp.auth;

/**
 * 此类有SQL排版，禁止格式化代码
 * 
 * @author Wayne.Wang<5waynewang@gmail.com>
 * @since 11:46:42 AM Dec 5, 2013
 */
public interface SqlStatics {
	
	// 获取所有资源
	String LIST_VISIBLE_RESOURCE = 
	"SELECT\n" +
	"	id,\n" +
	"	`name`,\n" +
	"	base_url,\n" +
	"	base_action,\n" +
	"	para_url,\n" +
	"	action_name,\n" +
	"	is_leaf,\n" +
	"	`level`,\n" +
	"	is_public,\n" +
	"	parent_id,\n" +
	"	order_num\n" +
	"FROM\n" +
	"	sys_resource\n" +
	"WHERE\n" +
	"	is_visible = TRUE\n" +
	"ORDER BY\n" +
	"	order_num";

	// 获取所有权限
	String LIST_ALL_PERMISSION = 
	"SELECT\n" +
	"	a.base_url,\n" +
	"	a.action_name,\n" +
	"	a.`level`,\n" +
	"	c.`value`\n" +
	"FROM\n" +
	"	sys_resource a,\n" +
	"	sys_resource_operation_rela b,\n" +
	"	sys_operation c\n" +
	"WHERE\n" +
	"	a.id = b.resource_id\n" +
	"AND b.operation_id = c.id\n" +
	"AND a.is_leaf = TRUE";

	// 获取用户权限
	String LIST_PERMISSION_BY_LOGIN_NAME = 
	"SELECT\n" +
	"	b.base_url,\n" +
	"	b.action_name,\n" +
	"	b.`level`,\n" +
	"	c.`value`\n" +
	"FROM\n" +
	"	sys_user_permission a,\n" +
	"	sys_resource b,\n" +
	"	sys_operation c\n" +
	"WHERE\n" +
	"	a.resource_id = b.id\n" +
	"AND a.operation_id = c.id\n" +
	"AND b.is_leaf = TRUE\n" +
	"AND a.login_name = ?\n" +
	"UNION ALL\n" +
	"	SELECT\n" +
	"		a.base_url,\n" +
	"		a.action_name,\n" +
	"		a.`level`,\n" +
	"		c.`value`\n" +
	"	FROM\n" +
	"		sys_resource a,\n" +
	"		sys_resource_operation_rela b,\n" +
	"		sys_operation c\n" +
	"	WHERE\n" +
	"		a.id = b.resource_id\n" +
	"	AND b.operation_id = c.id\n" +
	"	AND a.is_public = TRUE\n" +
	"	AND a.is_leaf = TRUE";
	
	// 获取不需要登录的公共资源
	String LIST_NEED_NOT_LOGIN_RESOURCE = 
	"SELECT\n" +
	"	a.base_url,\n" +
	"	a.action_name,\n" +
	"	c.`value`\n" +
	"FROM\n" +
	"	sys_resource a,\n" +
	"	sys_resource_operation_rela b,\n" +
	"	sys_operation c\n" +
	"WHERE\n" +
	"	a.id = b.resource_id\n" +
	"AND b.operation_id = c.id\n" +
	"AND a.is_public = TRUE\n" +
	"AND a.need_login = FALSE";
}
